package com.itgaohe.controller;

import com.itgaohe.dao.entity.ShopComments;
import com.itgaohe.service.ShopCommentsService;
import com.itgaohe.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/shop-comment")
@Tag(name = "商店评论管理", description = "用户相关操作")
public class ShopCommentsController {

    @Autowired
    private ShopCommentsService  shopCommentsService;

    /**
     * 根据商铺id查询商铺评论
     */
    @Operation(summary = "根据商铺id查询商铺评论")
    @GetMapping("/{shopId}")
    public Result queryShopCommentsByShopId(@PathVariable("shopId") Long shopId) {
        List<ShopComments> shopComments = shopCommentsService.queryShopCommentsByShopId(shopId);
        return Result.ok(shopComments);
    }

    /**
     * 商铺评论创建gv
     */
    @Operation(summary = "商铺评论创建gv")
    @PostMapping
    public Result createShopComments(@RequestBody ShopComments shopComments) {
        boolean result = shopCommentsService.save(shopComments);
        if(result){
            return Result.ok();
        }
        return Result.fail("商铺评论创建失败");
    }

}
